class Solution:
	# @param {integer[]} nums
	# @param {integer} k
	# @return {boolean}
	def containsNearbyDuplicate(self, nums, k):
		dup = {}
		for i in range(len(nums)):
			if nums[i] in dup:
				dup[nums[i]].append(i)
			else:
				dup[nums[i]] = [i]
		for vs in dup.itervalues():
			if len(vs) > 1:
				inds = sorted(vs)
				for j in range(1, len(vs)):
					if inds[j] - inds[j-1] <= k:
						return True
		return False

if __name__ == '__main__':
	so = Solution()
	nums = [1,2,3,2,3]
	print so.containsNearbyDuplicate(nums, 2)